package com.zhangc.blog.admin.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhangc.blog.admin.entity.BlogCategoryEntity;
import com.zhangc.blog.admin.entity.BlogInfoEntity;
import com.zhangc.blog.admin.mapper.BlogCategoryMapper;
import com.zhangc.blog.admin.mapper.BlogInfoMapper;
import com.zhangc.blog.base.constants.SysConfigConstants;

/**
 * 功能描述:<br>
 *
 * @author wx:fdzhangc
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
@Service
public class BlogCategoryServiceImpl extends ServiceImpl<BlogCategoryMapper, BlogCategoryEntity> {
    @Autowired
    private BlogInfoMapper blogInfoMapper;

    public boolean clearCategory(BlogCategoryEntity blogCategory) {
        BlogInfoEntity blogInfo = new BlogInfoEntity()
                .setBlogCategoryId(Integer.valueOf(SysConfigConstants.DEFAULT_CATEGORY.getConfigField()))
                .setBlogCategoryName(SysConfigConstants.DEFAULT_CATEGORY.getConfigName());
        LambdaUpdateWrapper<BlogInfoEntity> updateWrapper = Wrappers.<BlogInfoEntity>lambdaUpdate()
                .eq(BlogInfoEntity::getBlogCategoryId, blogCategory.getCategoryId());
        blogInfoMapper.update(blogInfo, updateWrapper);
        return retBool(baseMapper.deleteById(blogCategory.getCategoryId()));
    }
}
